package com.daocao.ds.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.daocao.ds.R;
import com.daocao.ds.api.model.MessageListModel;
import com.daocao.ds.util.TimeUtil;

import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class MyMessageAdapter extends ItemAdapter<MessageListModel.DatasBean, MyMessageAdapter.DefaultHolder> {


    public MyMessageAdapter(Context context) {
        super(context);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_my_message, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        MessageListModel.DatasBean item = getItem(position);
        holder.txtTitle.setText(item.title);
        holder.txtContent.setText(item.content);
        if (item.is_read.equals("1")) {
            holder.imgStatus.setImageResource(R.mipmap.img_message_old);
        } else {
            holder.imgStatus.setImageResource(R.mipmap.img_message_new);
        }
        holder.txtTime.setText(TimeUtil.format(new Date(Long.valueOf(item.created_at) * 1000)));
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_status)
        ImageView imgStatus;
        @BindView(R.id.txt_title)
        TextView txtTitle;
        @BindView(R.id.txt_time)
        TextView txtTime;
        @BindView(R.id.txt_content)
        TextView txtContent;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onSuccess();
    }
}
